//
//  UIButton+YMAdditions.swift
//  YMToolKit
//
//  Created by YDWY on 2017/4/20.
//  Copyright © 2017年 YDWY. All rights reserved.
//

import Foundation
import UIKit

extension UIButton {

    
    
    
    
    /// 创建UIButton
    ///
    /// - Parameters:
    ///   - title: 标题
    ///   - fontSize: 字体大小
    ///   - normalColor: 正常颜色
    ///   - highlightedColor: 高亮颜色
    class func ym_createButton(title:String, fontSize:CGFloat, normalColor:UIColor?, highlightedColor:UIColor?) -> UIButton{
       
       return  self.ym_createButton(title: title, fontSize: fontSize, normalColor: normalColor ?? UIColor.black, highlightedColor: highlightedColor ?? UIColor.black, backgroundImageName: nil)
    }
    
    
    
    
    /// 创建UIButton
    ///
    /// - Parameters:
    ///   - title: 标题
    ///   - fontSize: 字体大小
    ///   - normalColor: 正常颜色
    ///   - highlightedColor: 高亮颜色
    ///   - backgroundImageName: 背景图片的名称
    /// - Returns: 返回
    class func ym_createButton(title:String, fontSize:CGFloat, normalColor:UIColor, highlightedColor:UIColor, backgroundImageName:String?) -> UIButton{
        
        let button = UIButton()
        button.setTitle(title, for: .normal)
        button.setTitleColor(normalColor, for: .normal)
        button.setTitleColor(highlightedColor, for: .selected)
        
        button.titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        
        if backgroundImageName != nil {
            
            button.setBackgroundImage(UIImage(named: backgroundImageName!), for: .normal)
            let backgroundImageNameHL = backgroundImageName! + "_highlighted"
            button.setBackgroundImage(UIImage(named: backgroundImageNameHL), for: .selected)
        }
        
        return button
        
    }
    
    
    class func ym_createButton(imageName:String, backgroundImageName:String) ->UIButton{
       
        let button = UIButton()
        
        button.setImage(UIImage(named: imageName), for: .normal)
        let  imageNameHL = imageName + "_highlighted"
        button.setImage(UIImage(named: imageNameHL), for: .selected)
        
        
        button.setBackgroundImage(UIImage(named: backgroundImageName), for: .normal)
        let backgroundImageNameHL = backgroundImageName + "_highlighted"
        button.setBackgroundImage(UIImage(named: backgroundImageNameHL), for: .selected)
        
        
        button.sizeToFit()

        return button
    }
    
    
    
    
}
